# 用户名和密码的一些潜规则
# 字符大小写
# 长度限制
# 数字范围
# 手机
# 邮箱
# 常用正则表达式
# 腾讯QQ号从10000开始：[1-9][0-9]{4,}
# 只能输入汉字：“^[\u4e00-\u9fa5]{1,8}$” 取一到八个汉字
# 只能输入由数字和26个英文字母组成的字符串：“^[A-Za-z0-9]+$”
# 验证用户密码：“^[a-zA-Z]\w{7,17}$” 正确格式:以字母开头，长度在8-18位之间，只能包含字符，数字和下划线


import re


RE_USER_INFO = {}
USER_INFO = {}
PERSONAL_INFO = []


#定义用户信息规则
RE_NICKNAME = re.compile(r'[a-zA-Z0-9]\w+')
RE_REALNAME = re.compile(r'^[\u4e00-\u9fa5]{2,4}$')
RE_IDCARD = re.compile(r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$')  # 18位身份证对象
RE_PHONE = re.compile(r'13\d\d{8}|14[5,7,9]\d{8}|15[0,1,2,3,5,6,7,8,9]\d{8}|166\d{8}|17[1,2,3,5,6,7,8]\d{8}|18\d{8}|19[8,9]\d{8}|\d{3}-\d{8}|\d{4}-\d{7}')  # 电话对象
RE_EMAIL = re.compile(r'^[\da-z]+([\-\.\_]?[\da-z]+)*@[\da-z]+([\-\.]?[\da-z]+)*(\.[a-z]{2,})+$')  # 邮箱对象
RE_PASSWORD = re.compile(r'^[a-zA-Z]\w{7,17}$')

# 定义用户信息规则字典
RE_USER_INFO['昵称'] = RE_NICKNAME
RE_USER_INFO['真实姓名'] = RE_REALNAME
RE_USER_INFO['身份证号'] = RE_IDCARD
RE_USER_INFO['电话'] = RE_PHONE
RE_USER_INFO['邮箱'] = RE_EMAIL
RE_USER_INFO['密码'] = RE_PASSWORD



def login():
    '''注册和登录验证'''
    try:
        print('用户信息验证'.center(30, '-'))
        ID = 0
        is_add = True
        while (is_add):
            for key_CH, re_obj in RE_USER_INFO.items():
                text = input(f'{key_CH}:')
                result = re_obj.match(text)  
                if result:
                    print('验证通过')
                    print(result.group())
                    PERSONAL_INFO.append(f'{key_CH}:{result.group()}')
                    if len(PERSONAL_INFO) == 6:
                        ID += 1
                        USER_INFO[ID] = PERSONAL_INFO
                        # TODO:USER_INFO作为每个用户信息的存储和后续的调用
                        print(f'''user{ID}_info：{PERSONAL_INFO}''')
                        print(USER_INFO[1][3])
                        print('注册成功！：y:继续注册，n：退出')
                        is_add = input().strip() == 'y'
                else:
                    while True:
                        print('验证失败，格式错误，请重新输入')
                        text = input(f'{key_CH}:')
                        result = re_obj.match(text)  
                        if result:
                            print('验证通过')
                            print(result.group())
                            PERSONAL_INFO.append(f'{key_CH}:{result.group()}')
                            break
                        else:
                            continue
                        
                        
    except Exception as e:
        print(e)


def main():
    login()

if __name__ == "__main__":
    main()    